package com.longrise.common.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import com.longrise.common.R;


/**
 * Created by callxkj on 16/7/5.
 * 客服的蒙版view  后来增加二维码扫描蒙版 新闻详情蒙版
 */
public class CustomerServiceGuideView extends FrameLayout {

    private static final String TAG = "CustomerServiceGuideView";
    private final Context mContext;
    private int[] mCircleLocation;

    public static final int CUSTOMERSERVICE = 1;
    public static final int QRcode = 2;
    private GuideType mType;
    private int mMode;


    public CustomerServiceGuideView(Context context) {
        this(context, null);
    }

    public CustomerServiceGuideView(Context context, AttributeSet attrs) {
        this(context, null, 0);
    }

    public CustomerServiceGuideView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    public enum GuideType {
        //        CUSTOMERSERVICE, //客服
//        NEWSDETAILCOMMENT, //资讯详情页评论提示页
//        TKCALENDAR, //题库日历
//        MINE,
        BYSHARE_TIPS, //保易网分享
    }

    private void initView() {
        setBackgroundColor(getResources().getColor(R.color.app_shadow));
    }

    /**
     * 设置园的位置
     */
    public void setCircleLocation(int[] location, GuideType type) {
        this.mType = type;
        this.mCircleLocation = location;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mCircleLocation != null) {
//            if (mType !=GuideType.MINE) {
//                Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
//                PorterDuffXfermode porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
//                paint1.setXfermode(porterDuffXfermode);
//                paint1.setAntiAlias(true);
//                RectF rectF = new RectF(mCircleLocation[0], mCircleLocation[1], mCircleLocation[2], mCircleLocation[3]);
//                canvas.drawArc(rectF, 0, 360, true, paint1); //挖空
//                Paint paintdashed = new Paint(Paint.ANTI_ALIAS_FLAG);
//                paintdashed.setStyle(Paint.Style.STROKE);
//                paintdashed.setColor(Color.WHITE);
//                paintdashed.setStrokeWidth(1);
//                PathEffect effects = new DashPathEffect(new float[]{10, 10}, 0);
//                paintdashed.setPathEffect(effects);
//                canvas.drawArc(rectF, 0, 360, true, paintdashed); //画边缘线
//            }
//            if (mType == GuideType.NEWSDETAILCOMMENT) { //新闻详情页
//                Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
//                Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.comment);
//                int width = bitmap.getWidth();
//                int height = bitmap.getHeight();
//                int left = mCircleLocation[0] - width;
//                int top = mCircleLocation[1] - height;
//                canvas.drawBitmap(bitmap, left, top, paint2);
//            } else if (mType == GuideType.TKCALENDAR) { //题库的日历
//                Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
//                Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.tkcalendar);
//                int width = bitmap.getWidth();
//                int height = bitmap.getHeight();
//                int left = mCircleLocation[0] - width;
//                int top = mCircleLocation[3];
//                canvas.drawBitmap(bitmap, left, top, paint2);
//            }else if(mType == GuideType.MINE){
//                Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
//                Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.tips_aboutme1);
//                int dif1 = ScreenUnit.dip2px(mContext, 5);
//                int dif2 = ScreenUnit.dip2px(mContext, 12);
//                int left = mCircleLocation[0]-dif1;
//                int top = mCircleLocation[1]-dif2;
//                canvas.drawBitmap(bitmap,left,top,paint2);
//                Bitmap bitmap2 = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.tips_aboutme2);
//                int dif3 = ScreenUnit.dip2px(mContext, 8);
//                int dif4 = ScreenUnit.dip2px(mContext, 18);
//                int height2 = bitmap2.getHeight();
//                int left2 = mCircleLocation[2]+dif3;
//                int top2 = mCircleLocation[3]-height2+dif4;
//                canvas.drawBitmap(bitmap2,left2,top2,paint2);
//            }else
            if (mType == GuideType.BYSHARE_TIPS) {
                Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
                Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.insyi_lead);
                int width = bitmap.getWidth();
                int left = mCircleLocation[0] - width;
                int top = mCircleLocation[3];
                canvas.drawBitmap(bitmap, left, top, paint2);
            }
        }
    }
}
